package Java7_Concurrency_Cookbook.thread_executor_framework.future_task_done;

import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

/**
 * @author lixiangke
 * @date 2017/11/20
 */
public class ExecutableTask implements Callable<String> {
    private String name;

    public ExecutableTask(String name) {
        this.name = name;
    }

    @Override
    public String call() throws  InterruptedException {
        long duration = (int) new Random().nextInt(10);
        System.out.printf("%s: Waiting %d seconds for results\n", name, duration);
        TimeUnit.SECONDS.sleep(duration);
        return "Hello, world. I'm " + name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
